package PTA_JAVA.JavaA.Javademo20;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PersonSortable[] p = new PersonSortable[n];
        for (int i = 0; i < n; i++) {
            p[i] = new PersonSortable(sc.next(), sc.nextInt());
        }
        Arrays.sort(p);
        for(PersonSortable i:p){
            System.out.println(i.toString());
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
    }
}
class PersonSortable implements Comparable{
    private String name;
    private int age;

    public PersonSortable() {
    }

    public PersonSortable(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return this.name+"-"+this.age;
    }

    @Override
    public int compareTo(Object obj) {
        PersonSortable o =(PersonSortable) obj;
        if(this.name.compareTo(o.name)==0){
            return this.age-o.age;
        }else{
            return this.name.compareTo(o.name);
        }
    }
}
